<template>
  <avue-form :option="option" v-model="form" @submit="submit">
    <template slot="group2Header">
      <li class=" el-icon-info avue-group__icon " style=" display:flex;">
        <h1 class=" avue-group__title " style="padding-top:2px;padding-left:4px ">一般状况(可同步项 选填)</h1>
      </li>
      <!-- <el-button style="width: 100px;text-align:center; margin-left:60%;padding:10px 0px" @click="syn" type="primary">同步</el-button> -->

    </template>
  </avue-form>
</template>
<script>
import option from '@/const/cust/health/health'
import { getStore } from '@/util/store'
import { findObj, saveObj, findxy } from '@/api/cust/health/health'
import { validatenull } from '@/util/validate'
export default {
  data() {
    return {
      option: option(this),
      form: {
        jktjid: null,
        grjbxxid: null,
        jkdn: ''
      }
    }
  },
  watch: {
    'form.jcxmzz'(value) {
      const data = this.validatenull(value) ? value : value.split(',')
      var flag = Array.isArray(data) ? data.includes('25') : data === '25'
      if (flag) {
        this.option.group[0].column[3].display = true
      } else {
        this.option.group[0].column[3].display = false
      }
    }
  },
  computed: {},
  created() {
    this.form.grjbxxid = this.$route.query.grjbxxid
    this.form.jktjid = this.$route.query.id
    this.form.sfzhm = this.$route.query.sfzh
    this.jkdn = getStore({ name: 'jkdn' })
    this.getTjb()
  },
  methods: {
    submit() {
      this.form.tmcode = this.jkdn.tmcode
      this.form.name = this.jkdn.name
      saveObj(this.form).then(data => {
        this.from = data.data
        this.$message({
          showClose: true,
          message: '保存成功',
          type: 'success'
        })
      })
    },
    getTjb() {
      findObj(this.form).then(res => {
        if (res.data.code == 0 && res.data.data != null) {
          this.form = res.data.data[0]
        }
        if (validatenull(this.form.jcxmzz)) {
          this.form.jcxmzz = '1'
        }
        if (validatenull(this.form.lnrjkztzwpg)) {
          this.form.lnrjkztzwpg = '1'
        }
        if (validatenull(this.form.lnrshzlnlzwpg)) {
          this.form.lnrshzlnlzwpg = '1'
        }
      })
    },
    syn() {
      findxy({
        jktjid: this.form.jktjid,
        grjbxxid: this.form.grjbxxid,
        sfzhm: this.form.sfzhm
      }).then(res => {
        if (res.data.code != 0) {
          this.$message({
            showClose: true,
            message: res.data.msg,
            type: 'error'
          })
        } else {
          this.form = res.data.data
          this.$message({
            showClose: true,
            message: '同步成功',
            type: 'success'
          })
        }
      })
    }
  }
}
</script>